"""
example06 - 排序

冒泡排序：元素两两比较，如果前面的元素大于后面的元素，就交换两个元素的位置

搅拌排序（鸡尾酒） ---> 选做作业

Author: Administrator
Date: 2024/1/9
"""

# nums = [35, 12, 99, 58, 67, 42, 49, 31, 73]
# nums = [9, 1, 2, 3, 4, 5, 6, 7, 8]
nums = [2, 3, 4, 5, 6, 7, 8, 9, 1]

for i in range(1, len(nums)):
    swapped = False
    for j in range(0, len(nums) - i):
        if nums[j] > nums[j + 1]:
            nums[j], nums[j + 1] = nums[j + 1], nums[j]
            swapped = True
    if not swapped:
        break

print(nums)